package com.example.uniplugin_demo;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;

import io.dcloud.common.core.permission.PermissionControler;
import io.dcloud.feature.uniapp.annotation.UniJSMethod;
import io.dcloud.feature.uniapp.common.UniModule;

public class Huo15DemoModule extends UniModule {
    final private static String TAG="Huo15DemoModule";
    private static final int REQUEST_CODE=0x1203;
    private Activity activity;
    private String[] mPermissions;

    @UniJSMethod
    public void startLocation(JSONObject options){
        boolean isStart = (Boolean) options.get("is_start");

    }
    @UniJSMethod(uiThread = true)
    public void requestPermissions() {
        if (mUniSDKInstance.getContext() != null) {
            activity = (Activity) mUniSDKInstance.getContext();
            PermissionControler.requestPermissions(activity, mPermissions, REQUEST_CODE);
        }
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == REQUEST_CODE) {
            for (int i = 0; i < permissions.length; i++) {
                String preName = permissions[i];
                int granted = grantResults[i];
                Log.d(TAG, "权限名称：" + preName + ", granted=" + granted);
                if (granted!= PackageManager.PERMISSION_GRANTED){
                }
            }

        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
